<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<title>扫码登录获取信息</title>
</head>
<body>

<div align="center" id="img">
</div>
<div align="center" id="countdown">请扫码登录</div>
<div align="center" id="message"></div>
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
	var Token = '';
	var key = '';
	$.ajax({
        url:"{:url('admin/Ceshi/QRCode')}",
		type:'get',
		timeout:"3000",
		dataType: "json",
		success:function(data){
			var obj = eval("("+data+")");
			if(obj['start'] = 1){
				document.getElementById('img').innerHTML = '<img height="150px" width="150px" src="'+obj['img']+'" />';
				Token = obj['Token'];
				key = obj['key'];
				window.onload = loadmsg();
			}else{
				alert('发生错误');
			}
		},
		error:function(err){
			alert('发生错误');
		}
	});


    function loadmsg() {
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "{:url('admin/state/Token',array('Token'=>$Token,'key'=>$key))}",
            timeout: 10000, //ajax请求超时时间10s
            success: function (data, textStatus) {
                //从服务器得到数据，显示数据并继续查询
				var obj = eval("("+data+")");
				if (obj['start'] == 3) {
					$("#img").hide();
					$("#countdown").html("登录成功,获取信息成功！</br>");
					var htm = "";
					for(var p in obj){
						if(p != 'start'){
							if(p == '头像'){
								htm += '<tr height="24px"><td><img height="80px" width="80px" src="'+obj[p]+'" /></td><td>';
							}else if(p == '买家信用图片'){
								htm += '<tr><td><img src="'+obj[p]+'" /></td><td>';
							}else{
								htm += '<tr height="24px"><td>'+p+':' + unescape(obj[p])+'</td><td>';
							}
						}
					}
					$("#message").append(htm);
					second--;
				}else{
					if(obj['start'] == 0){
						alert('发生错误');
						return 0;
					}else if(obj['start'] == 2){
						$("#countdown").html("扫描成功");
					}
					setTimeout("loadmsg()", 1000);
                }
            },
            //Ajax请求超时，继续查询
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                if (textStatus == "timeout") {
                    setTimeout("loadmsg()", 1000);
                } else { //异常
                    setTimeout("loadmsg()", 4000);
                }
            }
        });
    }





</script>
</body>
</html>